package logic

import (
	"context"
	"hzjt-oam/rpc/sys/internal/svc"
	"hzjt-oam/rpc/sys/model"
	"hzjt-oam/rpc/sys/pb"
	"time"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddSysRoleLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddSysRoleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddSysRoleLogic {
	return &AddSysRoleLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// -----------------------角色管理-----------------------
func (l *AddSysRoleLogic) AddSysRole(in *pb.AddSysRoleReq) (*pb.AddSysRoleResp, error) {
	var sys_role = &model.SysRole{
		Name:           in.Name,
		RoleType:       in.RoleType,
		CreateBy:       in.CreateBy,
		CreateTime:     time.Now().Unix(),
		LastUpdateBy:   in.CreateBy,
		LastUpdateTime: time.Now().Unix(),
		DelFlag:        0,
		Status:         in.Status,
	}

	_, err := l.svcCtx.RoleModel.Insert(l.ctx, sys_role)

	if err != nil {
		return nil, err
	}
	return &pb.AddSysRoleResp{}, nil
}
